# _*_ coding: utf8
"""
author: ning.luo
create_date: 2019/12/11
last_update: 2019/03/11
"""

import requests
import json

class SupplierOffline():
    '''供应商下线流程测试'''

    def __init__(self):
        self.base_url = "http://test-api.intra.casstime.com/merchant-service"
        self.headers = {'Content-Type': 'application/json'}

    def supplier_apply_offline(self, **body):
        '''供应商申请下线'''
        url = self.base_url + "/apply/offline"
        response = requests.post(url, data=json.dumps(body), headers=self.headers)
        assert response.status_code == 200, "状态码错误：%s，结果：%s" % (response.status_code, response.text)
        print(response.text)
        print("申请成功！")

    def expander_examine(self, **body):
        '''拓展审核'''
        url = self.base_url + "/apply/offline/audit"
        response = requests.post(url, data=json.dumps(body), headers=self.headers)
        assert response.status_code == 200, "状态码错误：%s，结果：%s" % (response.status_code, response.text)
        print(response.text)
        print("审核成功！")

    def query_offline_info(self, **params):
        '''根据店铺id查询主动下线申请信息详情'''
        url = self.base_url + "/apply/detail/bystoreid"
        response = requests.get(url, params=params, headers=self.headers)
        assert response.status_code ==200, "状态码错误：%s，结果：%s" % (response.status_code, response.text)
        print(response.text)
        print("根据店铺id查询主动下线申请信息详情！")

    def send_offline_file(self, **body_data):
        '''发送下线涵'''
        url = self.base_url + "/offline/letter/send"
        response = requests.post(url, data=json.dumps(body_data), headers=self.headers)
        assert response.status_code == 200, "状态码错误：%s，结果：%s" % (response.status_code, response.text)
        print(response.text)
        print("发送下线涵！")

    def query_offline_list(self, **params):
        '''根据店铺id查询下线清单列表'''
        url = self.base_url + "/offline/checklist/bystoreid"
        response = requests.get(url, params=params, headers=self.headers)
        assert response.status_code == 200, "状态码错误：%s，结果：%s" % (response.status_code, response.text)
        print(response.text)
        print("根据店铺id查询下线清单列表！")

    def update_offline_list_status(self, body_data):
        '''根据下线清单类型更新清单列表状态'''
        url = self.base_url + "/offline/checklist/bystoreid"
        response = requests.put(url, data=body_data, headers=self.headers)
        assert response.status_code ==200, "状态码错误：%s，结果：%s" % (response.status_code, response.text)
        print(response.text)
        print("根据下线清单类型更新清单列表状态！")

    def query_list_info_by_storeId(self, **params):
        '''根据店铺id查询单个店铺下线详情信息'''
        url = self.base_url + "/offline/detail/bystoreid"
        response = requests.get(url, params=params)
        assert response.status_code == 200,  "状态码错误：%s，结果：%s" % (response.status_code, response.text)
        print(response.text)
        print("根据店铺id查询单个店铺下线详情信息！")

    def query_list_info_by_storeIds(self, body_data):
        '''根据店铺id批量查询店铺下线详情信息'''
        url = self.base_url + "/offline/detail/storeids"
        response = requests.post(url, data=json.dumps(body_data), headers=self.headers)
        assert response.status_code == 200, "状态码错误：%s，结果：%s" % (response.status_code, response.text)
        print(response.text)
        print("根据店铺id批量查询店铺下线详情信息！")

    def node_change_by_storeID(self, body_data):
        '''根据店铺id和当前节点更新下线流程'''
        url = self.base_url + "/offline/nodechange/bystoreid"
        response = requests.put(url, data=json.dumps(body_data), headers=self.headers)
        assert response.status_code == 200, "状态码错误：%s，结果：%s" % (response.status_code, response.text)
        print(response.text)
        print("根据店铺id批量查询店铺下线详情信息！")



if __name__ == "__main__":
    so = SupplierOffline()
    storeID = 'GZZQ0001'
    companyID = '100_100735'
    body_off = {
        "applyReason": "不想干了，咋地",
        "companyId": companyID,
        "promoterId": "zqlbx",
        "promoterName": "李宝相",
        "storeId": storeID
    }
    body_off1 = {
        "applyReason": "不想干了，咋地",
        "companyId": "100_100620",
        "promoterId": "bsmjg",
        "promoterName": "毛建刚",
        "storeId": "BS000001"
    }
    body_off2 = {
        "applyReason": "不想干了，咋地",
        "companyId": "N8kBrM2gOQSYLSQ4i1m",
        "promoterId": "CS190510055006",
        "promoterName": "康解",
        "storeId": "1J9w8967"
    }
    body_examine = {
        "auditReason": "不准下",
        "auditStatus": "AUDIT_FAIL",
        "auditTime": "2019-12-10",
        "storeId": storeID,
        "userLoginId": "luoning",
        "userName": "骆宁"
    }
    body_examine1 = {
        "auditReason": "滚蛋吧",
        "auditStatus": "AUDIT_SUCCESS",
        "auditTime": "2019-12-11",
        "storeId": storeID,
        "userLoginId": "luoning",
        "userName": "骆宁"
    }
    params_info = {"storeId":storeID}
    body_file = {
        "noticeContent": "这是个下线涵通知",
        "offlineLetterUrl": "https://cass-upload.oss-cn-shenzhen.aliyuncs.com/test/1570764760813_1182499229790093316_1182499229790093317.pdf",
        "offlineType": "MERCHANT_APPLICATION",
        "storeId": storeID,
        "userLoginId": "ksmgg",
        "userName": "米海峰"
    }
    body_update_status = {
        "storeId":storeID,
        "listType":"OUT_COMPLETE_ORDER"
    }
    body_node = {
        "storeId":storeID,
        "offlineNode": "",
        "userLoginId": ""
    }
    body_several_stores = ['BJDHS001','GZZQ0001']

    # 下线申请
    so.supplier_apply_offline(**body_off)

    # 拓展审核
    so.expander_examine(**body_examine1)

    # 查询下线详情
    so.query_offline_info(**params_info)

    # 发送下线涵
    so.send_offline_file(**body_file)

    # 查询下线清单
    so.query_offline_list(**params_info)

    # 更新下线清单状态
    so.update_offline_list_status(**body_update_status)

    # 查询单个店铺下线详情信息
    so.query_list_info_by_storeId(**params_info)

    # 查询多个店铺下线详情信息
    so.query_list_info_by_storeIds(body_several_stores)

    # 更新节点
    # so.node_change_by_storeID(**body_node)